<template>
    <div class="manage">
      <!-- 项目信息 -->
  <el-dialog
  title="活动信息"
  :visible.sync="dialogVisible"
  width="50%">
  <div class="itemArea"  style="font-size:18px">
    <div class="top" style="display:flex;justify-content:space-around">
      <div class="top-l" style="width:200px;height:200px">
        <img style="width:100%;height:100%" :src="evUrl+form.item_pic"/>
      </div>
      <div class="top-r" style="padding-top:18px;margin-bottom:10px">
        <div style="margin-bottom:10px">活动标题：{{form.item_tit}}</div>
        <div style="margin-bottom:10px">服务时长：{{form.service_time}}</div>
        <div style="margin-bottom:10px">联系人：{{form.contacts}}</div>
        <div style="margin-bottom:10px">手机号码：{{form.phone}}</div>
        <div style="margin-bottom:10px">岗位名称：{{form.station}}</div>
        <div style="margin-bottom:10px">岗位人数：{{form.num}}</div>
        <div style="margin-bottom:10px">活动地址：{{form.addr}}</div>
        <div style="margin-bottom:10px">活动描述：{{form.item_describe}}</div>
        <div style="margin-bottom:10px">报名开始时间：{{form.startTime}}</div>
        <div style="margin-bottom:10px">报名截止时间：{{form.endTime}}</div>
        <div>活动类型：{{form.item_type}}</div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
                <h5>审核状态：{{exaStatus(openStatus)}}</h5>
                <el-button size="mini" @click="pass">通过</el-button>
                <el-button size="mini" type="primary" @click="unpass">驳回</el-button>
            </span>
  </div>
</el-dialog>
        <div class="manage-header" style="height:45px">
            <!-- <el-button @click="handleAdd" type="primary">
                + 新增
            </el-button> -->
            <!-- form搜索区域 -->
            <el-form style="height:100%" :inline="true" :model="userForm">
                <el-form-item>
                    <el-input placeholder="请输入活动名称" v-model="userForm.name"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">查询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="common-tabel">
            <el-table
                stripe
                border
                :cell-style="{textAlign:'center',padding:'7px'}"
                :header-cell-style="{background:'#87CEFA',color:'#ffffff',textAlign:'center',padding:'7px'}"
                height="100%"
                :data="tableData"
                style="width: 100%">
                <el-table-column
                    show-overflow-tooltip
                    prop="item_tit"
                    label="活动名称"
                    width="130">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="item_describe"
                    label="活动描述"
                    width="100">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="s_realName"
                    label="学校"
                    width="100">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="num"
                    label="人数"
                    width="78">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="station"
                    label="岗位名称"
                    width="100">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="addr"
                    label="地址"
                    width="130">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="endTime"
                    label="截止时间"
                    width="200">
                    <template slot-scope="scope">
                      <span>{{scope.row.endTime? (scope.row.endTime+'').slice(0,19).replace('T',' '):'否'}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="exa_status"
                    label="审核状态"
                    width="108">
                    <template slot-scope="scope">
                      <span>{{exaStatus(scope.row.exa_status)}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="addr"
                    label="操作"
                    width="218">
                    <template slot-scope="scope">
                        <el-button size="mini" type="info" @click="details(scope.row)">查看</el-button>
                        <!-- <el-button size="mini" @click="handleEdit(scope.row)">审核</el-button> -->
                        <!-- <el-dropdown>
                        <el-button type="primary" size="mini">
                             审核
                       </el-button>
                       <el-dropdown-menu slot="dropdown">
                       <el-dropdown-item>通过</el-dropdown-item>
                       <el-dropdown-item>驳回</el-dropdown-item>
                       </el-dropdown-menu>
                       </el-dropdown> -->
                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                        <!-- <el-dropdown style="margin-left:12px;" @command="(command)=>{
                          handleCommand(command,scope.row)}">
                        <el-button type="primary" size="mini">
                             审核
                       </el-button>
                       <el-dropdown-menu slot="dropdown">
                       <el-dropdown-item command="pass">通过</el-dropdown-item>
                       <el-dropdown-item command="unpass">驳回</el-dropdown-item>
                       </el-dropdown-menu>
                       </el-dropdown> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pager">
                <el-pagination
                 @size-change="handleSizeChange"
                 @current-change="handleCurrentChange"
                 :current-page.sync="pageData.page"
                 :page-sizes="[10, 20, 30, 40]"
                 :page-size="pageData.limit"
                 layout="sizes, prev, pager, next"
                 :total="total">
    </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { adminGetPub, examPub, deletePub, editUser, delUser } from '../api/record'
export default {
  data () {
    return {
      evUrl: this.$evUrl,
      dialogVisible: false,
      openStatus: '',
      form: {
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      value1: '',
      rules: {
        name: [
          { required: true, message: '请输入姓名' }
        ],
        age: [
          { required: true, message: '请输入年龄' }
        ],
        sex: [
          { required: true, message: '请选择性别' }
        ],
        birth: [
          { required: true, message: '请选择出生日期' }
        ],
        addr: [
          { required: true, message: '请输入地址' }
        ]
      },
      tableData: [],
      modalType: 0, // 0表示新增的弹窗， 1表示编辑
      total: 0, // 当前的总条数
      pageData: {
        page: 1,
        limit: 10
      },
      userForm: {
        name: ''
      }
    }
  },
  computed: {},
  methods: {
    exaStatus (status) {
      if (status === '1') {
        return '审核通过'
      } else if (status === '0') {
        return '审核不通过'
      } else {
        return '待审核'
      }
    },
    // 审核通过
    pass () {
      examPub({ newVal: '1', itemId: this.form.itemId }).then(() => {
        this.openStatus = '1'
        // console.log('11111', this.form.itemId)
        this.getList()
      })
    },
    // 审核不通过
    unpass () {
      this.$prompt('请输入驳回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        examPub({ newVal: '0', itemId: this.form.itemId, reasonVal: value }).then(() => {
          this.openStatus = '0'
          // console.log('11111', this.form.itemId)
          this.getList()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消'
        })
      })
    },
    handleEdit (row) {
      this.modalType = 1
      this.dialogVisible = true
      // 注意需要对当前行数据进行深拷贝，否则会出错
      this.form = JSON.parse(JSON.stringify(row))
    },
    handleDelete (row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletePub({ itemId: row.itemId }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          // 重新获取列表的接口
          this.getList()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleAdd () {
      this.modalType = 0
      this.dialogVisible = true
    },
    // 获取列表的数据
    getList () {
      // 获取的列表的数据
      adminGetPub({ params: { ...this.userForm, ...this.pageData } }).then(({ data }) => {
        // console.log(data)
        this.tableData = data.list

        this.total = data.count || 0
      })
    },
    // 页码
    handleSizeChange (val) {
      this.pageData.limit = val
      this.getList()
    },
    // 选择页码的回调函数
    handleCurrentChange (val) {
      // console.log(val, 'val')
      this.pageData.page = val
      this.getList()
    },
    // 选择页码的回调函数
    // handlePage (val) {
    //   // console.log(val, 'val')
    //   this.pageData.page = val
    //   this.getList()
    // },
    // 列表的查询
    onSubmit () {
      this.pageData.page = 1
      this.getList()
    },
    // 详情列表
    details (row) {
      this.form = JSON.parse(JSON.stringify(row))
      this.form.activityTime = [row.startTime, row.endTime]
      this.openStatus = row.exa_status
      // console.log(row)
      // const detailInfo = `项目名称：${row.itemName}联系人:${row.contacts}联系电话:${row.phone}支教岗位:${row.station}
      // 人数:${row.num},开始时间:${row.startTime}结束时间:${row.endTime}地址：${row.addr}描述:${row.describe}`
      // this.$alert(detailInfo, '详情', {
      //   confirmButtonText: '确定'
      // callback: action => {
      //   this.$message({
      //     type: 'info',
      //     message: `action: ${action}`
      //   })
      // }
      // })
      this.dialogVisible = true
    }
  },
  mounted () {
    this.getList()
  }
}
</script>
<style lang="less" scoped>
.manage {
    height: 90%;
    .manage-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .common-tabel {
        position: relative;
        height: calc(100% - 1px);
        .pager {
            position: absolute;
            bottom: 1px;
            right: 20px;
            background-color: #ffffff;
        }
    }
}
</style>
